<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,com.hz.framework.util.*" %>
<%@ include file="../common/commonJS.jsp" %>
<%@ include file="../common/commonLabel.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int row = Integer.parseInt((String)request.getAttribute("row"));
String year = (String)request.getAttribute("year");
String month = (String)request.getAttribute("month");
%>

<HTML>
<HEAD>
<TITLE>客户订单统计表</TITLE>
<META content="text/html;charset=UTF-8" http-equiv=Content-Type>
<style type="text/css">
/* 操作列的宽度 */
.boxtd{
	width: 18%;
}
</style>
<script type="text/javascript">
function doRowsum(){
	var days = <%=row %>;
	var numsum = 0;
	var monsum = 0;
	for(var j=1;j<=days;j++){
		var num = document.all["num"+j];
		var mon = document.all["mon"+j];
		var nums = 0;
		var mons = 0;
		if(num){
			if(num.length){
				for(var i =0;i<num.length;i++){
					nums += (num[i].value-0);
					mons += (mon[i].value-0);
				}
			}else{
				nums += (num.value-0);
				mons += (mon.value-0);
			}
		}
		document.getElementById("numsum"+j).innerHTML = round(nums,2);
		document.getElementById("monsum"+j).innerHTML = round(mons,2);
		numsum += nums;
		monsum += mons;
	}
	document.getElementById("numsum").innerHTML = round(numsum,2);
	document.getElementById("monsum").innerHTML = round(monsum,2);
}

function DoSel(y,m,d){
	if(m==""){
		document.all["year"].value = y;
		document.all["month"].value = d;
		document.forms[0].submit();
	}
}
function doPrint(){
	var oldaction = document.forms[0].action;
	document.forms[0].action = "<%=path %>/docs/ys_statistics/clientorder_statprint.jsp";
	document.forms[0].submit();
	document.forms[0].action = oldaction;
}
</script>
</HEAD>
<BODY onload="doRowsum()">
<form action="<%=path %>/clientorderstat.action" method="post" name="myform">
<table  width="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr>
     <td>
     <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" class="MainBody">
      <tr>
        <td width="760" class="MainBody_title"><hello:forValue type="title" /></td>
        <td></td>
      </tr>
        <tr>
			<td colspan="2" >
			<table border="0" width="100%" cellpadding="0" cellspacing="0" style="margin: 10 50 10 0;">
          		<tr>
	          	<td align="right" width="50%">
      			请选择：<select name="year" >
      			<% for (int i = Integer.parseInt(DateUtil.getYear()); i >Integer.parseInt(DateUtil.getYear())-7; i--) { 
      						%>
      					<option value="<%=i %>" <%=String.valueOf(i).equals(year)?"selected":"" %>><%=i %>年</option>
      				<%} %>
      		    </select>&nbsp;&nbsp;
      		    <select name="month" >
      		    	<option value="">请选择</option>
      				<% for (int i = 1; i <13; i++) {  %>
      					<option value="-<%=i<10?"0"+i:i %>" <%=String.valueOf(i<10?"-0"+i:"-"+i).equals(month)?"selected":"" %>><%=i %>月</option>
      				<%} %>
      		    </select>&nbsp;&nbsp;
		    	</td>
				<td align="left" >&nbsp;&nbsp;
					<input type="submit" class="btn" value="查询信息">
					&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="导出" class="btn" onclick="doPrint()"/>
				</td>
				<td width="30%">&nbsp;&nbsp;
					<input type="hidden" name="operate" value="sel">
					<input type="hidden" name="row" value="<%=row %>">
				</td>
				</tr>
			</table>
		<%
		List info = (List)request.getAttribute("listinfo");//数据信息
		%>
		<%-- 列表信息 全局 --%>
		<div style="width: 1000;height: 380px;overflow: auto; ">
		<table cellpadding="0" cellspacing="0" style="width: 120%;" class="MainBody_table">
			<tr align="center">
				<th nowrap="nowrap" width="100px" onclick="doOrder('fundflag')" rowspan="2" style="cursor: pointer;">客户名称</th>
		<%	for(int i=1;i<=row;i++){ %>
				<th onclick="DoSel('<%=year %>','<%=month %>','<%=i<10?"-0"+i:"-"+i %>')" colspan="2"><%=i<10?"&nbsp;"+i:i %></th>
		<% 	}%>
				<th colspan="2">总合计</th>
			</tr>
			<tr align="center">
		<%	for(int i=1;i<=row;i++){ %>
				<th nowrap="nowrap">数量</th>
				<th nowrap="nowrap">金额</th>
		<% 	}%>
				<th nowrap="nowrap">总数量</th>
				<th nowrap="nowrap">总金额</th>
			</tr>
		<%if(info!=null){ 
			for(int i=0;i<info.size();i++){
				Map minfo = (Map)info.get(i);
		%>
			<tr align="center" onmouseover="this.style.backgroundColor='#EEF7FD';" onmouseout="this.style.backgroundColor='';">
		        <td ><%=minfo.get("clientName")==null?"":minfo.get("clientName") %></td>
		        <%
		        double numsum = 0;
		        double monsum = 0;
		        for(int j=1;j<=row;j++){
		        	double numone = minfo.get("num"+j)==null?0:Double.parseDouble((String)minfo.get("num"+j));
		        	double monone = minfo.get("mon"+j)==null?0:Double.parseDouble((String)minfo.get("mon"+j));
		        	numsum += numone;
		        	monsum += monone;
		        %>
		        <td ><%=CommonUtils.formatDouble(3,numone)%><input type="hidden" name="<%="num"+j %>" value="<%=numone%>"></td>
		        <td ><%=CommonUtils.formatDouble(3,monone)%><input type="hidden" name="<%="mon"+j %>" value="<%=monone%>"></td>
		        <%} %>
		        <td ><%=CommonUtils.formatDouble(3,numsum) %></td>
		        <td ><%=CommonUtils.formatDouble(3,monsum) %></td>
		   	</tr>
		   
		<% 	} %>
			<tr align="center" onmouseover="this.style.backgroundColor='#EEF7FD';" onmouseout="this.style.backgroundColor='';">
	        <td >单天合计：</td>
	        <%
	        for(int j=1;j<=row;j++){
	        %>
	        <td id="<%="numsum"+j %>"></td>
	        <td id="<%="monsum"+j %>"></td>
	        <%} %>
	        <td id="numsum"></td>
	        <td id="monsum"></td>
	   	</tr>
		<%}%>
		<c:if test="${empty listinfo}">
			<tr>
				<td colspan="<%=row*2+3 %>" align="center">暂时没有您可以浏览的信息</td>
			</tr>
		</c:if>
		</table>
		</div>
		<c:if test="${!empty listinfo}">
		<div style="margin-left: 20px;">
			<hello:AllPage />
		</div>
		</c:if>
		</td>
    </tr>
   </table>
    </td>
  </tr>
 </table>
</form>
</BODY>
</HTML>
